package com.zzyl.service.impl;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.DeviceDataPageReqDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.mapper.DeviceDataMapper;
import com.zzyl.service.DeviceDataService;
import com.zzyl.vo.DeviceDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class DeviceDataServiceimpl implements DeviceDataService {
    @Autowired
    private DeviceDataMapper deviceDataMapper;

    /**
     * 分页查询设备数据
     *
     * @param deviceDataPageReqDto
     * @return
     */
    @Override
    public PageResponse<DeviceDataVo> getPage(DeviceDataPageReqDto deviceDataPageReqDto) {
        PageHelper.startPage(deviceDataPageReqDto.getPageNum(), deviceDataPageReqDto.getPageSize());
        LocalDateTime localDateTimestart = LocalDateTimeUtil.of(deviceDataPageReqDto.getStartTime());
        LocalDateTime localDateTimeend = LocalDateTimeUtil.of(deviceDataPageReqDto.getEndTime());
        deviceDataPageReqDto.setEndDate(localDateTimeend);
        deviceDataPageReqDto.setStartDate(localDateTimestart);
        Page<DeviceDataVo> page = deviceDataMapper.getPage(deviceDataPageReqDto);
        return PageResponse.of(page, DeviceDataVo.class);
    }
}
